package com.learn.thread;

import jdk.nashorn.internal.ir.CallNode;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class BankAccount {
    public static void main(String[] args) {
        User user = new User();
        Thread thread1 = new Thread(user);
        Thread thread2 = new Thread(user);
        thread1.setName("甲");
        thread2.setName("乙");

        thread1.start();
        thread2.start();
    }

}

class User implements Runnable{

    public int account = 0;

    public ReentrantLock lock = new ReentrantLock();

    public void run() {
//        synchronized (this){
//            for (int i=0;i< 3;i++){
//                account+=1000;
//                System.out.println(Thread.currentThread().getName() +account);
//            }
//        }

        lock.lock();
        for (int i = 0; i< 3;i++){
            account+=1000;
            System.out.println(account);
        }
        lock.unlock();
    }

}